import 'package:base_plugin/base_plugin.dart';
import 'package:dio/dio.dart';

class HttpAssetService {
  static Future<Response> assetList() async {
    return await BaseConfig.httpBase.get('/api/assets', {});
  }

  static Future<Response> createAsset({
    String name,
    String category,
    String currency_code,
    String type,
    int type_id,
    String purchased_at,
    num price,
    num book_value_after,
    String depreciation_type,
    int lifespan,
    List attachment_ids,
  }) async {
    return await BaseConfig.httpBase.postJson('/api/assets', {
      "name": name,
      "category": category,
      "currency_code": currency_code,
      "type": type,
      "type_id": type_id,
      "purchased_at": purchased_at,
      "price": price,
      "book_value_after": book_value_after,
      "depreciation_type": depreciation_type,
      "lifespan": lifespan,
      'attachment_ids': attachment_ids ?? [],
    });
  }

  static Future<Response> updateAsset(
    int id, {
    String name,
    String category,
    String currency_code,
    String type,
    int type_id,
    String purchased_at,
    num price,
    num book_value_after,
    String depreciation_type,
    int lifespan,
    List attachment_ids,
  }) async {
    return await BaseConfig.httpBase.putJson('/api/assets/$id', {
      "name": name,
      "category": category,
      "currency_code": currency_code,
      "type": type,
      "type_id": type_id,
      "purchased_at": purchased_at,
      "price": price,
      "book_value_after": book_value_after,
      "depreciation_type": depreciation_type,
      "lifespan": lifespan,
      'attachment_ids': attachment_ids ?? [],
    });
  }

  static Future<Response> deleteAsset(int id) async {
    return await BaseConfig.httpBase.deleteJson('/api/assets/$id', {});
  }

  static Future<Response> sellAsset(
    int id, {
    String sell_at,
    String sell_currency_code,
    String notes,
    num sell_price,
    List attachment_ids,
  }) async {
    return await BaseConfig.httpBase.postJson('/api/assets/$id/sell', {
      "sell_at": sell_at,
      "sell_currency_code": sell_currency_code,
      "sell_price": sell_price,
      "notes": notes,
      'attachment_ids': attachment_ids ?? [],
    });
  }

  static Future<Response> disposeAsset(
    int id, {
    String notes,
    String disposed_at,
    List attachment_ids,
  }) async {
    return await BaseConfig.httpBase.postJson('/api/assets/$id/dispose', {
      "disposed_at": disposed_at,
      "notes": notes,
      'attachment_ids': attachment_ids ?? [],
    });
  }

  static Future<Response> showAsset(int id) async {
    return await BaseConfig.httpBase.get('/api/assets/$id', {});
  }
}
